Key:
Save
Speagram Home
|
tutorial
|
use me
|
live interface
|
documentation
|
developer's corner
|
links
|
contact
SYMBOLIC DATA ANALYSIS IN SPEAGRAM
Done
Hide
Edit
Run
This part
New
Up
Down
Delete
Help
…
TEMPLAT_TEXT
Done
Hide
Edit
Run
This part
New
Up
Down
Delete
Help
…
On this page of our tutorial we want to introduce you to symbolic analysis features present in Speagram. In fact you have been using some of them all the time in previous parts of the tutorial without noticing. Let us therefore start with the following examples that illustrate how Speagram can handle rewriting in the presence of uninstantiated variables. %$ Load state library:/basic. New variable x as ?a. New variable y as ?a. x = x. if true then x else y. if false then x else y. if true then 17 else y. $%
Done
Hide
Edit
Run
This part
New
Up
Down
Delete
Help
…
The features presented above allow Speagram to simplify basic expressions with variables, but their scope is limited. To make rewriting reasonably efficient we could not implement too complex simplification mechanisms into basic rewriting. Look at the example below to see that basic rewriting does not always yield the simplest form of a term, as it can not deduce %PxP% in this case. %$ if y then x else x. $%
Done
Hide
Edit
Run
This part
New
Up
Down
Delete
Help
…
We are going to show how the problems with basic simplification can be addressed later, but for now let us show how simplification can be used to search through terms. There is a basic %PSearch for XP% command in Speagram that allows to search for all substitutions of variables in %PXP% that satisfy the given property. During this search Speagram uses simplification and induction over types of the variables, so it is guaranteed that all solutions will be found.
Done
Hide
Edit
Run
This part
New
Up
Down
Delete
Help
…
To see for yourself that search indeed works in Speagram run the following tests. Especially look at the last test-case to see how Speagram combines symbolic simplification and induction. %$ New variable b as boolean. New variable c as boolean. Search for b = b. Search for b = c. Search for (b and c) = true. Search for (b or c) = true. $%
Done
Hide
Edit
Run
This part
New
Up
Down
Delete
Help
…
The previous search examples are quite basic, but let us introduce a more interesting one. The search function of Speagram can be used only to a limited height of terms and in this way applied to infinite types to look for simple solutions. To see how this feature can be used we are going to load the Speagram state after the tutorial about [[Tutorial Example: Symbolic Differentiation.php|symbolic differentiation]] and look for simple solutions of a differential equation. The presentation of the results is still very raw as we are working on improving our implementation of this part of Speagram. %$ Load state file:/"Tutorial Example: Symbolic Differentiation". New variable e as expression. Search for small simplify (e'*x) = simplify (2*e) and not (e = 0). $%
Done
Hide
Edit
Run
This part
New
Up
Down
Delete
Help
…
After we looked at search features of Speagram let us proceed to the most powerful part of symbolic analysis methods present in Speagram - the possibility to use logic. Speagram was built from scratch with the intention to make it possible to meaningfully support automated reasoning and the use of logic. Even though our implementation of some parts of the logic engine is at very early stages, we are quite convinced that the design that we have chosen is right. Before we describe how logic can be used in Speagram let us tell how the general design of the logic part of Speagram is done and why we find it promising. First of all, one of the main problems when reasoning about functional programs in the use of mathematical induction. Many automated deduction systems start just with deduction and try to add mathematical induction on top of it. While this is possible in theory, it tends not to work too well in practice. In Speagram we start with typed terms as basic object, so simple mathematical induction is in a way built-in. Then we use a version of determinisation algorithm for tree automata to cope with inductive reasoning. Only at this point we modify this algorithm so that it works on formulas and does not explicitly use the automata, so it can be combined with deductive methods. This together with basic simplification built into rewriting engine allows us to have quite efficient logic support. In this way we can handle all formulas where only tree-automatic function are used and even more when deduction or a previously proved lemma is used to simplify the non-automatic part.
Done
Hide
Edit
Run
This part
New
Up
Down
Delete
Help
…
Before we go on to the examples let us introduce the syntax of logic formulas in Speagram. The formulas are constructed from equalities on normal Speagram terms, boolean connectives and quantifiers. The full syntax (built into Speagram) is as follows. %P Element ?a ''='' ?a as logic formula. Element ''not'' logic formula as logic formula. Element logic formula ''and'' logic formula as logic formula. Element logic formula ''or'' logic formula as logic formula. Element ''exists'' ?a '':'' logic formula as logic formula. Element ''for'' ''all'' ?a '':'' logic formula as logic formula. P% Inside Speagram you will normally use formulas in three situations: as axioms to add new axioms to Speagram, for searching (as shown above) and to define and compute new relations. By default Speagram tries to understand the relation you throw at it, so it tries to construct a function that computes this relation. We are going to see more complex example below, let us now just introduce the syntax. %$ Load state library:/core. New variable b as boolean. Relation ''is'' boolean ''true?'' given by b = true. Is false true?. $%
Done
Hide
Edit
Run
This part
New
Up
Down
Delete
Help
…
Basic relations on finite types are nice but not too useful. Speagram can handle relations on infitite types. Let us realize our promise and show how Speagram can automatically generate functions. We are going to define binary numbers and the %P+P% function and then let Speagram automatically construct the %P<=P% relation. Here comes the %P+P% on binary numbers. %$ Load state library:/core. New class ''binary number''. New element ''0'' as binary number. New element ''1'' as binary number. New element binary number ''0'' as binary number. New element binary number ''1'' as binary number. New variable n as binary number. New variable m as binary number. New variable k as binary number. New function binary number ''+'' binary number as binary number. See (n+(m0)) preferred to (n+m)0. See (n+(m1)) preferred to (n+m)1. See ((n+m)+k) preferred to (n+(m+k)). Let 0 + n be n. Let n + 0 be n. Let 1 + 1 be 10. Let n0 + 1 be n1. Let n1 + 1 be (n+1)0. Let 1 + n0 be n1. Let 1 + n1 be (n+1)0. Let n0 + m0 be (n+m)0. Let n0 + m1 be (n+m)1. Let n1 + m0 be (n+m)1. Let n1 + m1 be (n+1+m)0. $%
Done
Hide
Edit
Run
This part
New
Up
Down
Delete
Help
…
Here is the main point - we let Speagram define %P<=P% automatically. Previously we had to write the rules by hand, which is error-prone and boring. %$ Relation binary number ''<='' binary number given by exists k : n + k = m. $%
Done
Hide
Edit
Run
This part
New
Up
Down
Delete
Help
…
See that the new relation indeed works as a function now. %$ 10 <= 11. 100 <= 100. 111 <= 10. $%
Done
Hide
Edit
Run
This part
New
Up
Down
Delete
Help
…
''Summary'' We hope that we convinced you that Speagram offers advanced methods to analyse you data and functions. Our implementation of this part od Speagram still has some problems, but you could see that Speagram can do quite difficult things including automatic program generation, which is hardly present in any other tool.
Saved XSLT Stylesheet
Saved SRGS Grammar